package com.insta.formation.library.service.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.insta.formation.library.Properties;
import com.insta.formation.library.dao.JdbcTools;
import com.insta.formation.library.dao.impl.BookDaoImpl;
import com.insta.formation.library.dao.impl.ExemplaryDaoImpl;
import com.insta.formation.library.dao.impl.RentDaoImpl;
import com.insta.formation.library.dao.impl.UserDaoImpl;
import com.insta.formation.library.model.IRentBook;
import com.insta.formation.library.model.IUser;

public class ServiceFactoryImpl {
	
	final private static Logger LOGGER = LoggerFactory.getLogger(BookDaoImpl.class);
	

	public void ShowLibrary()  
	{
		BookDaoImpl book = new BookDaoImpl();
		try {
			String query = "SELECT id FROM " + Properties.BOOK_TABLE ;
			Connection conn = JdbcTools.INSTANCE.getConnection();
			PreparedStatement stmt = conn.prepareStatement(query);

			ResultSet rs = stmt.executeQuery();
			if (rs.next()) {
				System.out.println(book.find(rs.getInt(1)));
			}
			stmt.close();

		} catch (SQLException e) {
			LOGGER.error(e.getMessage());
			book = null;
		}
			
	}

	public boolean RentBook(IRentBook rentbook)
	{
		RentDaoImpl rent = new RentDaoImpl();
		try
		{
			rent.create(rentbook);
			return true;
		}
		catch (Exception e)
		{
			LOGGER.error(e.getMessage());
		}
		return false;
	}
	
	public void DeleteOwnCount(IUser user)
	{
		UserDaoImpl user_dao = new UserDaoImpl();
		user_dao.delete(user);
	}
	

	
}
